﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
namespace ERP.Classes
{
    public class cs_erp_dvtInfo
    {
        private int _id_dvt;
        private string _donvitinh;
        private string _ghichu;

        public cs_erp_dvtInfo(int id_dvt, string donvitinh, string ghichu)
        {
            this._id_dvt = id_dvt;
            this._donvitinh = donvitinh;
            this._ghichu = ghichu;

        }
        public cs_erp_dvtInfo()
        {
            this._id_dvt = 0;
            this._donvitinh = " ";
            this._ghichu = " ";

        }
        public int id_dvt
        {
            get
            {
                return this._id_dvt;
            }
            set
            {
                this._id_dvt = value;
            }
        }
        public string donvitinh
        {
            get
            {
                return this._donvitinh;
            }
            set
            {
                this._donvitinh = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[4];
            paraName[0] = "@id_dvt";
            paraName[1] = "@donvitinh";
            paraName[2] = "@ghichu";
            paraName[3] = "@option";
            object[] paraValue = new object[4];
            paraValue[0] = this._id_dvt;
            paraValue[1] = this._donvitinh;
            paraValue[2] = this._ghichu;
            paraValue[3] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 4, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_DVT", option);
        }

        
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_DVT", "id_dvt = " + this._id_dvt);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_dvt = Convert.ToInt32(ds.Tables[0].Rows[0]["id_dvt"].ToString().Trim());
                this._donvitinh = ds.Tables[0].Rows[0]["donvitinh"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_dvt, donvitinh, ghichu"
                + " from ERP_DVT";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

    }
}
